package com.example.sfm.controller.teacher;

import com.example.sfm.constant.MessageConstants;
import com.example.sfm.pojo.dto.StudentRecordsQueryDto;
import com.example.sfm.result.Result;
import com.example.sfm.service.IStudentRecordsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sfm
 * @since 2025-03-07
 */
@RestController("teacherStudentRecordsController")
@RequestMapping("/user/teacher/student-records")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "学生档案管理", description = "教师对学生档案的操作接口")
public class StudentRecordsController {
    private final IStudentRecordsService recordsService;

    /**
     * 分页查询档案
     */
    @GetMapping("/list")
    @Operation(summary = "分页查询学生档案", description = "根据查询条件分页查询学生档案信息")
    public Result<?> listRecords(@ParameterObject StudentRecordsQueryDto dto) {
        log.info("查询学生档案: {}", dto);
        return Result.success(recordsService.listRecords(dto), MessageConstants.SELECT_OK);
    }

    /**
     * Excel导出学生档案
     */
    @GetMapping("/export")
    @Operation(summary = "导出学生档案到 Excel", description = "根据查询条件导出学生档案信息到 Excel 文件")
    public void exportExcel(@Parameter(description = "HTTP 响应对象") HttpServletResponse response,
                            @ParameterObject StudentRecordsQueryDto dto) {
        log.info("导出学生档案: {}", dto);
        recordsService.exportExcel(response, dto);
    }
}